﻿using Consulta.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TrabajoFinal.Models;
using WebMatrix.WebData;

namespace Consulta.Controllers
{
    public class ClientController : Controller
    {
        //
        // GET: /Client/

        ContextoDatos db = new ContextoDatos();
        List<Darsena> listedDarsenas = new List<Darsena>();

        [Authorize(Roles = "Client")]
        public ActionResult ListedDarsena(LDarsena dars)
        {
            if (dars.hasta.CompareTo(DateTime.MinValue)==0)
            {
                dars.hasta = DateTime.MaxValue;
            }
            foreach (var i in db.Darsenas.ToList())
            {
                if (i.empresa.cod == dars.codEmp)/* && dars.desde <= i.fecha && i.fecha >= dars.hasta)*/
                {
                    if (dars.desde <= i.fecha && i.fecha <= dars.hasta)
                    {
                        listedDarsenas.Add(i);
                    }
                }
            }
            ViewBag.desde = dars.desde;
            ViewBag.hasta = dars.hasta;
            return View(listedDarsenas);
        }

        [Authorize(Roles="Client")]
        public ActionResult LogedClient()
        {
            ViewBag.usuario = db.Usuarios.Find(WebSecurity.CurrentUserId);
            return View();
        }
    }
}
